/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.classnet.db;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 *
 * @author karltinawi
 */
@Entity
@Table(name = "user")
@NamedQueries({@NamedQuery(name = "User.findByEmail", query = "SELECT u FROM User u WHERE u.email = :email")})
public class User implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "email", nullable = false)
    private String email;
    @Lob
    @Column(name = "password", nullable = false)
    private byte[] password;
    @ManyToMany(mappedBy = "recipientCollection")
    private Collection<Post> postCollection;
    @ManyToMany(mappedBy = "recipientCollection1")
    private Collection<Post> postCollection1;
    @JoinTable(name = "enrolled_on", joinColumns = {@JoinColumn(name = "user", referencedColumnName = "email")}, inverseJoinColumns = {@JoinColumn(name = "subject", referencedColumnName = "subject"), @JoinColumn(name = "code", referencedColumnName = "code"), @JoinColumn(name = "section", referencedColumnName = "section")})
    @ManyToMany
    private Collection<Course> courseCollection;
    @JoinTable(name = "user_group_member", joinColumns = {@JoinColumn(name = "member", referencedColumnName = "email")}, inverseJoinColumns = {@JoinColumn(name = "user_group", referencedColumnName = "id")})
    @ManyToMany
    private Collection<UserGroup> userGroupCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user1")
    private Collection<Phone> phoneCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
    private Collection<UserGroup> userGroupCollection1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "sender")
    private Collection<Post> postCollection2;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user1")
    private Collection<Email> emailCollection;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "user1")
    private Admin admin;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Collection<ActRequest> actRequestCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user1")
    private Collection<Friend> friendCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user2")
    private Collection<Friend> friendCollection1;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "user1")
    private Profile profile;

    public User() {
    }

    public User(String email) {
        this.email = email;
    }

    public User(String email, byte[] password) {
        this.email = email;
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public byte[] getPassword() {
        return password;
    }

    public void setPassword(byte[] password) {
        this.password = password;
    }

    public Collection<Post> getPostCollection() {
        return postCollection;
    }

    public void setPostCollection(Collection<Post> postCollection) {
        this.postCollection = postCollection;
    }

    public Collection<Post> getPostCollection1() {
        return postCollection1;
    }

    public void setPostCollection1(Collection<Post> postCollection1) {
        this.postCollection1 = postCollection1;
    }

    public Collection<Course> getCourseCollection() {
        return courseCollection;
    }

    public void setCourseCollection(Collection<Course> courseCollection) {
        this.courseCollection = courseCollection;
    }

    public Collection<UserGroup> getUserGroupCollection() {
        return userGroupCollection;
    }

    public void setUserGroupCollection(Collection<UserGroup> userGroupCollection) {
        this.userGroupCollection = userGroupCollection;
    }

    public Collection<Phone> getPhoneCollection() {
        return phoneCollection;
    }

    public void setPhoneCollection(Collection<Phone> phoneCollection) {
        this.phoneCollection = phoneCollection;
    }

    public Collection<UserGroup> getUserGroupCollection1() {
        return userGroupCollection1;
    }

    public void setUserGroupCollection1(Collection<UserGroup> userGroupCollection1) {
        this.userGroupCollection1 = userGroupCollection1;
    }

    public Collection<Post> getPostCollection2() {
        return postCollection2;
    }

    public void setPostCollection2(Collection<Post> postCollection2) {
        this.postCollection2 = postCollection2;
    }

    public Collection<Email> getEmailCollection() {
        return emailCollection;
    }

    public void setEmailCollection(Collection<Email> emailCollection) {
        this.emailCollection = emailCollection;
    }

    public Admin getAdmin() {
        return admin;
    }

    public void setAdmin(Admin admin) {
        this.admin = admin;
    }

    public Collection<ActRequest> getActRequestCollection() {
        return actRequestCollection;
    }

    public void setActRequestCollection(Collection<ActRequest> actRequestCollection) {
        this.actRequestCollection = actRequestCollection;
    }

    public Collection<Friend> getFriendCollection() {
        return friendCollection;
    }

    public void setFriendCollection(Collection<Friend> friendCollection) {
        this.friendCollection = friendCollection;
    }

    public Collection<Friend> getFriendCollection1() {
        return friendCollection1;
    }

    public void setFriendCollection1(Collection<Friend> friendCollection1) {
        this.friendCollection1 = friendCollection1;
    }

    public Profile getProfile() {
        return profile;
    }

    public void setProfile(Profile profile) {
        this.profile = profile;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (email != null ? email.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof User)) {
            return false;
        }
        User other = (User) object;
        if ((this.email == null && other.email != null) || (this.email != null && !this.email.equals(other.email))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.classnet.db.User[email=" + email + "]";
    }

}
